package com.carboy.launch.update;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

import com.carboy.launch.activity.column.ColumnMainActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

/***
 * @author james
 * @Package com.huixin.carnav.update
 * @Title: UpdateTimeThread.java
 * @Description 首次启动launcher更新网络时间
 * @date 2015-9-1
 * @version 1.0
 * 
 */
public class UpdateTimeThread implements Runnable {

	private Handler mHandler;

	public UpdateTimeThread(Handler mHandler) {
		this.mHandler = mHandler;
	}

	@Override
	public void run() {
		Message msg = Message.obtain();
		msg.what = ColumnMainActivity.HANDLER_UPDATATIME;
		Bundle mBundle = new Bundle();

		URL url;
		try {
			url = new URL("http://www.beijing-time.org");
			URLConnection uc = url.openConnection();// 生成连接对象
			uc.setConnectTimeout(5000);
			uc.connect(); // 发出连接
			long ld = uc.getDate(); // 取得网站日期时间
			if (ld != 0) {
				mBundle.putLong("time", ld);
			} else {
				mBundle.putLong("time", 0);
			}
		} catch (Exception e) {
			e.printStackTrace();
			mBundle.putLong("time", 0);
		}
		msg.setData(mBundle);
		mHandler.sendMessage(msg);
	}

}
